<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta content="text/html;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<meta http-equiv ="Pragma" content = "no-cache"/>
	<meta http-equiv="Cache-Control" content="no cache" />
	<meta http-equiv="Expires" content="0" />
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
	<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
	<meta name="apple-mobile-web-app-capable" content="yes"/>
	<meta name="format-detection" content="telephone=no"/>
	<script src="https://cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
	<link href="https://cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css" media="all"/>
	<link rel="stylesheet" type="text/css" href="../../css/fs.css" media="all"/>
	<script type="text/javascript" src="../../plugins/layui/layui.js"></script>
	<script type="text/javascript" src="../../plugins/jquery/jquery.min.js"></script>
	<script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
	<script type="text/javascript" src="../../plugins/home/common.js"></script>
	<script type="text/javascript" src="../../plugins/frame/js/fsDict.js"></script>
	<script type="text/javascript" src="../../plugins/frame/js/fs.js"></script>
	<script type="text/javascript" src="../../plugins/frame/js/frame.js"></script>
	<script type="text/javascript" src="../../scripts/home/yunhetong.js"></script>
	<script type="text/javascript" src="../../scripts/home/magerIndcInfo.js"></script>
</head>
<body>
<div >
	<div class="layui-fluid">
		<div class="layui-row layui-col-space1">
			<div class="layui-col-md12">
				<div class="layui-form-query">
					<form class="layui-form" id="query_form">
						<input type="hidden" name="contractId"/>
					</form>
				</div>
			</div>
			<div class="layui-col-md12">
				<div class="layui-row grid-demo">
					<div class="layui-col-md12">
						<a class="layui-btn" function="download"  href="" topTitle="新增" id="downloadHref" download>
							<!--<i class="layui-icon">&#xe654;</i>-->下载文件
						</a>
						<!--<button class="layui-btn" function="submit"  isMutiDml="1" isConfirm="1" confirmMsg="是否确定删除选中的数据？" inputs="id:">
							<i class="layui-icon">&#xe640;</i>加盖公章
						</button>		-->
						<button class="layui-btn" function="jiaGaiGongZhang"  inputs="id:" id="jiaGaiGongZhang">
							<!--<i class="layui-icon">&#xe640;</i>-->加盖公章
						</button>
						<button class="layui-btn layui-btn-danger" function="createZuoFei" id="createZuoFeiBtn">
							<!--<i class="layui-icon">&#x1002;</i>-->生成作废协议
						</button>
						<button class="layui-btn" style="background-color: blue" function="createAgain" id="createAgainBtn">
							<!--<i class="iconfont">&#xe74a;</i>-->再次生成
						</button>
						<button class="layui-btn" style="background-color: #9c9c9c" function="cancelZuoFei" id="cancelZuoFei">
							<!--<i class="layui-icon">&#x1002;</i>-->取消作废
						</button>
						<button class="layui-btn" style="background-color: green" function="history" id="history">
							<!--<i class="layui-icon">&#x1002;</i>-->历史记录
						</button>
						<!--<button class="layui-btn" function="kfapp">
							<i class="layui-icon">&#xe756;</i>测试
						</button>-->
					</div>
					<div class="layui-col-md12" id="myDiv">

						<iframe src="" frameborder="0" id="demoAdmin" style="width: 100%; height: 850px;padding-top:30px"></iframe>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
    var domain=getRootPath();
    var contractId=getQueryVariable('contractId');
    var reserveNo=getQueryVariable('reserveNo');
    var contractNum=getQueryVariable('contractNum');
    var currentUser=getCurrentLoginUser();
    //根据合同id查询作废协议列表
    var contractSts='';//合同状态
    $("#contractId").val(contractId);
    //作废协议编号
	var cancelContractId='';
	var cancelContractNum='';

    //测试
    layui.fsButton.test = function(elem,data,datagrid){
        datagrid.reload();
        alert("测试自定义按钮2"+JSON.stringify(datagrid));
    }
    //历史记录
    layui.fsButton.history = function(elem,data,datagrid){
        var param="?contractId="+contractId;
        var indexDialog=layer.open({
            type: 2,//类型，解析url
            title: '历史记录',
            /*            closeBtn: 0, //不显示关闭按钮
                        shadeClose: true,
                        shade: [0],*/
            id: (new Date()).valueOf(), //设定一个id，防止重复弹出 时间戳1280977330748
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '600px'],
            anim: 2,
            content: ['history.html'+param, 'no'], //iframe的url，no代表不显示滚动条
            end: function(){ //此处用于演示

            }
        });
        //弹出即全屏
        layer.full(indexDialog);
    }
    //加盖公章
    layui.fsButton.jiaGaiGongZhang = function(elem,data,datagrid){
        if(contractSts!='5'){
            messageInfo("请先联系客户签署协议");
            return;
		}else{
            var url=domain+"/api/v1/contractSignManager/jiaGai/gongzhang";
            var param={"contractId":contractId,"reserveNo":reserveNo,"currentUserId":currentUser,"cancelContractNum":cancelContractNum};
            var result=sendMyAjaxPost(url,param);
            if(result.code==0){
                layer.alert("操作成功", {
                    icon: 6,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                },function(){
                    //刷新列表
                    location.reload();
                })
            }else{
                //提示错误信息
                messageInfo(result.message);
            }
        }
    }
    //生成作废协议
    layui.fsButton.createZuoFei = function(elem,data,datagrid){
            //生成作废协议
                layer.prompt({title: '请填写作废原因', formType: 2}, function(text, index){
                    if(text==''){
                        alert('作废原因不能为空');
					}else{
                        var url=domain+"/api/v1/contractSignManager/create/zuoFeiXieYi";
                        var param={"contractId":contractId,"reserveNo":reserveNo,"currentUserId":currentUser,"cancelRemark":text};
                        var result=sendMyAjaxPost(url,param);
                        if(result.code==0||result.code==200){
                            layer.alert("操作成功", {
                                icon: 6,
                                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                            },function(){
                                //刷新列表
                                location.reload();
							})
						}else{
                            //提示错误信息
                            messageInfo(result.message);
						}

					}
                    layer.close(index);
                });



    }
    //再次生成
    layui.fsButton.createAgain = function(elem,data,datagrid){
        if(contractSts=='6'){
            messageInfo("当前作废合同已生效，不能再次生成");
            return;
        }else{
            layer.prompt({title: '请填写作废原因', formType: 2}, function(text, index){
                if(text==''){
                    alert('作废原因不能为空');
                }else{
                    var url=domain+"/api/v1/contractSignManager/create/again";
                    var param={"contractId":contractId,"cancelContractId":cancelContractId,"reserveNo":reserveNo,"currentUserId":currentUser,"cancelRemark":text};
                    var result=sendMyAjaxPost(url,param);
                    if(result.code==0){
                        layer.alert("操作成功", {
                            icon: 6,
                            skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                        },function(){
                            //刷新列表
                            location.reload();
                        })
                    }else{
                        //提示错误信息
                        messageInfo(result.message);
                    }
                }})

		}
    }
    //取消作废
    layui.fsButton.cancelZuoFei = function(elem,data,datagrid){
        if(contractSts=='6'){
            messageInfo("当前作废合同已生效，无法作废");
            return;
        }else{
            var url=domain+"/api/v1/contractSignManager/cancel/zuofei";
            var param={"contractId":contractId,"contractNum":contractNum,"operatorId":currentUser};
            var result=sendMyAjaxPost(url,param);
            if(result.code==0){
                layer.alert("操作成功", {
                    icon: 6,
                    skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                },function(){
                    //刷新列表
                    location.reload();
                })
            }else{
                //提示错误信息
                messageInfo(result.message);
            }
		}
    }
    $(document).ready(function(){
        var queryListUrl=domain+"/elecContCancelDtl/findAllList.shtml";
        var param={"contractId":contractId};
        var queryListResult=sendMyAjaxPost(queryListUrl,param);
        console.log("获取到的数据为====================="+JSON.stringify(queryListResult));
        if(queryListResult.code==0){
            //获取状态
            contractSts=queryListResult.data.contractSts;
            cancelContractId=queryListResult.data.cancelContractId;
            cancelContractNum=queryListResult.data.cancelContractNum;
            //隐藏生成作废协议按钮
			$("#createZuoFeiBtn").hide();
            download(contractId,queryListResult.data.cancelContractId);
            //download(contractId,'1909091100402982');
        }else{
            //暂无数据
			$("#myDiv").html("<div style='padding-top: 5px'><blockquote class=\"layui-elem-quote\">当前无作废合同</blockquote></div>");
			//只展示作废协议按钮，其他按钮隐藏
            $("#downloadHref").hide();//下载
			$("#jiaGaiGongZhang").hide();//加盖公章
			$("#createAgainBtn").hide();//再次生成
			$("#cancelZuoFei").hide();//取消作废
			$("#history").hide();//历史记录

        }

    });

    /**
     * @param contractId 合同id
     * @param cancelContractId 作废协议变化好
     */
    function download(contractId,cancelContractId){
        console.log("下载合同参数contractId=============="+contractId);
       $.ajax({
           url: domain+"/api/v2/yunhetong/download/contractCancel", //请求的url地址
           dataType: "json", //返回格式为json
           async: true, //请求是否异步，默认为异步，这也是ajax重要特性
           data: {
               "idType": "0",
               "idContent":cancelContractId,
			   "contractId":contractId
           }, //参数值
           type: "post", //请求方式
           beforeSend: function() {
               //请求前的处理
           },
           success: function(req) {
               console.log("下载合同作废协议返回结果==="+JSON.stringify(req));
               //请求成功时处理
               $("#demoAdmin").attr('src',req.data);
               $("#downloadHref").attr('href',req.data);
           },
           complete: function() {
               //请求完成的处理
           },
           error: function() {
               //请求出错处理
           }
       });
   }
</script>
</body>
</html>

